unit uCategoria;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, upai, FMTBcd, DB, DBClient, Provider, SqlExpr, Grids, DBGrids,
  StdCtrls, Mask, DBCtrls, Menus, dxCore, dxButton, ExtCtrls;

type
  TfCategoria = class(TfPai)
    lbl2: TLabel;
    dbedtDESCRICAO: TDBEdit;
    dbgrd1: TDBGrid;
    sds_grupo: TSQLDataSet;
    dsp_grupo: TDataSetProvider;
    ds_grupo: TClientDataSet;
    pnl1: TPanel;
    lbl3: TLabel;
    lbl4: TLabel;
    sds_grupoDESCCATEGORIA: TStringField;
    sds_grupoCOD_CATEGORIA: TIntegerField;
    sds_grupoCOD_FAMILIA: TIntegerField;
    ds_grupoDESCCATEGORIA: TStringField;
    ds_grupoCOD_CATEGORIA: TIntegerField;
    ds_grupoCOD_FAMILIA: TIntegerField;
    lbl1: TLabel;
    dbedtDESCRICAO1: TDBEdit;
    sds_grupoGRUPO: TStringField;
    ds_grupoGRUPO: TStringField;
    procedure btnGravarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fCategoria: TfCategoria;

implementation

uses UDM;

{$R *.dfm}

procedure TfCategoria.btnGravarClick(Sender: TObject);
begin
  if (ds_grupo.State = dsInsert) then
  begin
     if dm.c_6_genid.Active then
        dm.c_6_genid.Close;
     dm.c_6_genid.CommandText := 'SELECT CAST(GEN_ID(gen_categoria, 1) AS INTEGER) AS CODIGO FROM RDB$DATABASE';
     dm.c_6_genid.Open;
     ds_grupoCOD_CATEGORIA.AsInteger := dm.c_6_genidCODIGO.AsInteger;
     ds_grupoCOD_FAMILIA.AsInteger := dm.v_IDFAMILIA;
     dm.c_6_genid.Close;
  end;
  inherited;

end;

procedure TfCategoria.FormShow(Sender: TObject);
begin
//  inherited;
 Incluir := 'S';
 Excluir := 'S';
 Alterar := 'S';
 Cancelar := 'S';
 Procurar := 'S';
end;

end.
